package com.javasm.bootcrud01.config;

import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

public class CorsConfig implements WebMvcConfigurer {


    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/api/**")
                .allowedOrigins("http://localhost:8080")
                .allowedMethods("get","post","put","delete","options")
                .allowedHeaders("*")
                .allowCredentials(true)
                .maxAge(3600);//预检查请求缓存时间

        WebMvcConfigurer.super.addCorsMappings(registry);
    }
}
